package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.CremationFurnaceCameraEntity;

/**
 * 火化炉炕面摄像头信息表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class CremationFurnaceCameraProvider {

    /**
     * 增加CremationFurnaceCamera
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertCremationFurnaceCamera(@Param("entity") CremationFurnaceCameraEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cremation_furnace_camera ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" furnace_id ", " #{entity.furnaceId,jdbcType=INTEGER} ");
                VALUES(" ip_address ", " #{entity.ipAddress,jdbcType=VARCHAR} ");
                VALUES(" port_number ", " #{entity.portNumber,jdbcType=INTEGER} ");
                VALUES(" account ", " #{entity.account,jdbcType=VARCHAR} ");
                VALUES(" password ", " #{entity.password,jdbcType=VARCHAR} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改CremationFurnaceCamera
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateCremationFurnaceCamera(@Param("entity") CremationFurnaceCameraEntity entity) {
        return new SQL() {
            {
                UPDATE(" cremation_furnace_camera ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" furnace_id = #{entity.furnaceId,jdbcType=INTEGER} ");
                SET(" ip_address = #{entity.ipAddress,jdbcType=VARCHAR} ");
                SET(" port_number = #{entity.portNumber,jdbcType=INTEGER} ");
                SET(" account = #{entity.account,jdbcType=VARCHAR} ");
                SET(" password = #{entity.password,jdbcType=VARCHAR} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询CremationFurnaceCamera列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listCremationFurnaceCamera(@Param("entity") CremationFurnaceCameraEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,furnace_id,ip_address,port_number,account,password,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cremation_furnace_camera ");

                if (entity.getFurnaceId() != null) {
                    WHERE(" furnace_id = #{entity.furnaceId,jdbcType=INTEGER} ");
                }

                if (entity.getIpAddress() != null) {
                    WHERE(" ip_address = #{entity.ipAddress,jdbcType=VARCHAR} ");
                }

                if (entity.getPortNumber() != null) {
                    WHERE(" port_number = #{entity.portNumber,jdbcType=INTEGER} ");
                }

                if (entity.getAccount() != null) {
                    WHERE(" account = #{entity.account,jdbcType=VARCHAR} ");
                }

                if (entity.getPassword() != null) {
                    WHERE(" password = #{entity.password,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}